""" 数据库配置 """
from contextlib import contextmanager
# from flask_sqlalchemy import SQLAlchemy
from sqlalchemy.exc import SQLAlchemyError
from app.extensions import db

@contextmanager
def session_scope():
    """提供事务管理的数据库会话上下文"""
    session = db.session
    try:
        yield session
        session.commit()
    except SQLAlchemyError as e:
        session.rollback()
        raise e
    finally:
        session.close()
